package ari;
/**
 * Whole project comment.
 */
import robocode.Robot;
import robocode.RobotDeathEvent;
import robocode.ScannedRobotEvent;

/**.
 * 
 * Picks an enemy and follows them, but stops within 50 pixels of target.
 * 
 * @author Richard Akina
 *
 */
public class Follow02 extends Robot {
  String enemyName;
  
  /**
   * Turns robot right 10 degrees.
   */
  public void run() {
    while (true) {
      turnRight(10);
    }
  }
  
  /**
   * 
   * If the detected robot matches enemyName, the robot is pursued, however
   * this robot stays 50 pixels away from the target bot.
   * 
   * @param e The robot that is scanned.
   */
  public void onScannedRobot(ScannedRobotEvent e) {
    fire(5);
    /*if (enemyName != null && e.getName().equals(enemyName)) {
      if (e.getDistance() <= 50) {
        doNothing();
      }
      else {
        ahead(e.getDistance() - 50);
        fire(5);
      }
    } 
    */
    if (enemyName == null) {
      enemyName = e.getName();
      if (e.getDistance() <= 50) {
        fire(5);
        doNothing();
      }
      ahead(e.getDistance() - 50);
      fire(5);
    }
  }

  
  /**
   * 
   * On the death of the targeted bot, enemyName is made null.
   * @param e The robot that is detected.
   */
  public void onRobotDeath(RobotDeathEvent e) {
    enemyName = null;
  }

}
